<template>
  <div class="nearby">
    <div class="nearby-swipew">
      <maxSwiper :message='maxSwiper'/>
    </div>
    <div class="nearby-type">
      <div class="notice">
        <!-- 头部社区 -->
        <Header :message='weather' :list='listData' :defaultName='defaults' @getContent="Switching" />
        <!-- 导肮列表 -->
        <TabList :message='tabList' :call='mobile'/>
        <!-- 指南列表 -->
        <SwiperBusiness :message='typeData' :total='typeTotal'/>
      </div>
    </div>
    <footNavTwo/>
  </div>
</template>
<script>
import maxSwiper from './components/maxSwiper'
import Header from './components/header'
import footNavTwo from '@/components/footNavTwo'
import api from '../../api/api.js'
import TabList from './components/tabList'
import SwiperBusiness from './components/swiperBusiness'
export default {
  data(){
    return{
      showConfirm:false,
      infomobile: '',
      mobile: '',
      weather: {},
      ip: '',
      getcity: '',
      listData:[],
      itemData:[],
      defaults:'',
      maxSwiper : [],
      loading: true,
      id:'',
      typeData:[],
      typeTotal:null,
      tabList : [
        {
          path:'/communityType',
          imgSrc:require("@/assets/images/guide.png"),
          Text: '社区服务指南'
        },
        {
          path:'/communityList',
          imgSrc:require("@/assets/images/advise.png"),
          Text: '通知公告'
        },
        {
          path:'/dynamic',
          imgSrc:require("@/assets/images/dynamic.png"),
          Text: '社区动态'
        },
        {
          path:'/opinion',
          imgSrc:require("@/assets/images/opinion.png"),
          Text: '民意调查'
        },
        {
          path:'/AddAppointment',
          imgSrc:require("@/assets/images/subscribe.png"),
          Text: '服务预约'
        },
        // {
        //   path:undefined,
        //   imgSrc:require("@/assets/images/feedBack.png"),
        //   Text: '社区医院'
        // },
        {
          path:'/volunteer',
          imgSrc:require("@/assets/images/registration.png"),
          Text: '志愿者申请'
        },
        {
          path:'/declare',
          imgSrc:require("@/assets/images/declare.png"),
          Text: '健康申报'
        },
        {
          path:'/addHousehold',
          imgSrc:require("@/assets/images/live.png"),
          Text: '居住信息申报'
        },
        {
          path:'/addMerchants',
          imgSrc:require("@/assets/images/shops.png"),
          Text: '商铺信息申报'
        },
        {
          path:'/listen',
          imgSrc:require("@/assets/images/feedBack.png"),
          Text: '意见反馈'
        },
        // {
        //   path:undefined,
        //   imgSrc:require("@/assets/images/integral.png"),
        //   Text: '我的积分'
        // },
        {
          path:undefined,
          imgSrc:require("@/assets/images/mobile.png"),
          Text: '联系社区'
        },
      ],
      list : []
    }
  },
  created(){
    this.getIP()
    this.quarters()
    this.businesstype()
    this.communityMobile()
    this.communityImages()
  },
  methods:{
    // 顶部轮播
    communityImages(){
      this.$get(api.communityImages, {})
      .then((response) => {
        if(response.data.code===1){
          this.maxSwiper = response.data.data.list
        }
      })
      .catch((error) => {
        console.log(error);
      });
    },
    //获取社区
    quarters(){
      this.$get(api.communityList,{})
      .then((response) => {
        if(response.data.code==1){
          this.defaults = response.data.data.default_name
          console.log(this.defaults)
          this.listData = response.data.data.list
          this.listData.forEach((element,index) => {
            this.listData[index].text = element.name
            this.listData[index].textId = element.id
          });
        }
      })
      .catch((error) => {
        console.log(error);
      });
    },
    communityMobile(){
      this.$get(api.communityMobile,{})
      .then((response) => {
        if(response.data.code==1){
          this.mobile = response.data.data.mobile
        }
      })
      .catch((error) => {
        console.log(error);
      });
    },
    // 指南分类
    businesstype(){
       this.$toast.loading({
        duration: 0, // 持续展示 toast
        forbidClick: true,
        message: '加载中...',
      });
      this.$get(api.Category, {
        params: {
          pageNumber: 1,
          pageSize: 4,
          type: 4
        }
      })
      .then((response) => {
        this.typeData = response.data.data.list
        this.typeTotal = response.data.data.total
        this.$toast.clear();
      })
      .catch((error) => {
        this.$toast.clear();
        console.log(error)
      });
    },
    getIP(){
      //获取本地IP地址
      this.ip=localStorage.getItem('Ip')
      this.getLocation()
    },
   //获取IP城市areacode
    getLocation(){
      // 百度普通定位API
      this.$jsonp('https://api.map.baidu.com/location/ip?ip='+this.ip+'&ak=hlTOCwmv7dccdMhFXZLMYr1051QD2Vqs',{})
      .then((response) => {
        if(response.status==0){
          this.getcity = response.content.address_detail.city.split('市')[0]
          this.getareacode()
        }
      })
      .catch((error) => {
        console.log(error);
      });
    },
    getareacode(){
      this.$get('https://gfapi.mlogcn.com/function/v001/city?location='+this.getcity+'&items=10&area=china&key=DVlVa41T7j9ebeXWTDZK5FooZN4ypAEK',{})
        .then((response) => {
            this.areacode=response.data.areaList[0].areacode
            this.getweather()
        })
        .catch((error) => {
          console.log(error);
        });
    },
    //获取天气
    getweather(){
      // this.$get('https://www.tianqiapi.com/api/?version=v1&appid=82128415&appsecret=YLqA1Jo3&city='+this.getcity,{})
      this.$get('https://gfapi.mlogcn.com/weather/v001/now?areacode='+this.areacode+'&key=DVlVa41T7j9ebeXWTDZK5FooZN4ypAEK',{})
        .then((response) => {
          // 当前天气
          this.weather=response.data.result
        })
        .catch((error) => {
          console.log(error);
        });
    },
    // 选择需切换校区
    Switching(ResidentialId){
      // 参数为子组件传递的小区id
      this.$get(api.choose, {
        params: {
 　　     id: ResidentialId
        }
      })
      .then((response) => {
        window.location.reload();
      })
      .catch((error) => {
        console.log(error)
      });
    },
  },
  components:{
    maxSwiper,
    Header,
    footNavTwo,
    TabList,
    SwiperBusiness
  }
}
</script>
<style scoped>
.nearby{
  background: #fff;
  overflow: hidden;
}
.hear-text{
  font-size: .32rem;
  width: 100%;
  text-align: center;
}
</style>
